package com.markus.code.图.图2;

import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;

/**
 * Author:markusZhang
 * Date:Create in 2020/8/31 12:33
 * todo:
 */
public class GraphBfs {
    public void bfs(Node node){
        Deque<Node> deque = new LinkedList<>();
        HashSet<Node> set = new HashSet<>();
        deque.addLast(node);
        set.add(node);
        while (!deque.isEmpty()) {
            Node pop = deque.pollFirst();
            System.out.print(pop.value+" ");
            for (Node nextNode : pop.nextNodes) {
                if (!set.contains(nextNode)){
                    deque.addLast(nextNode);
                    set.add(nextNode);
                }
            }
        }
    }
}
